package cn.thoughtworks.school.services;

import cn.thoughtworks.school.entities.Event;
import cn.thoughtworks.school.entities.PV;
import cn.thoughtworks.school.repositories.EventRepository;
import cn.thoughtworks.school.repositories.PvRepository;
import cn.thoughtworks.school.utils.IpUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
@Slf4j
public class ActivityService {
  @Autowired
  private HttpServletRequest request;
  @Autowired
  private PvRepository pvRepository;

  @Autowired
  private EventRepository eventRepository;

  public void savePv(PV pv) {
    String ip = IpUtil.getIp(request);
    pv.setIp(ip);
    pvRepository.save(pv);
  }

  public void saveEvent(Event event) {
    eventRepository.save(event);
  }
}
